import api from "@/api/api";
import depot from "@/utils/depot.js";

export function checkAuth() {
	//#ifdef MP-WEIXIN
	let vue = this;
	let openId = uni.getStorageSync("openId");
	if (!openId) {
		console.log("login...")
		uni.login({
		  provider: 'weixin',  
		  success: async (res) => {
			  console.log(res)
		    if (res.code) {  
		      const code = res.code; 
			  let response = await depot.get(api.wechat("user/login"), {code: code});
			  console.log(response)
			  if (response && response.data && response.data.data) {
			  	let wechatUser = response.data.data;
			  	if (wechatUser && wechatUser.openId) {
					uni.setStorageSync("openId", wechatUser.openId);
			  	}
			  }
		    }  
		  }  
		});  
	}
	//#endif
}